package View;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.JComponent;

import Model.Color;

public class Square extends JComponent {
	private static final int HELP_SIZE = -10;
	private static final int HELP_POSITION = 5;
	private static final int POSITION = 0;
	private int size;
	private Color color;
	private Image image;
	private boolean help;
	private boolean selected;
	
	
	public Square(int size, Color color){
		this.size = size;
		this.color = color;
		image = null;
		this.setPreferredSize(new Dimension(size, size));
		help = false;
		selected = false;
	}
	
	public Color getColor() {
		return color;
	}

	public void setImage(Image image, Color team){
		this.image = image;
	}
	
	public Image getImage(){
		return image;
	}
	
	public void needHelp(boolean help){
		this.help = help;
	}
	
	public void setSelected(boolean selected){
		this.selected = selected;
	}
		
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		if(selected){
			g.setColor(java.awt.Color.GREEN);
			g.fillRect(POSITION, POSITION, size, size);
			g.setColor(java.awt.Color.BLACK);
			if(Color.White.equals(color)){
				g.setColor(java.awt.Color.WHITE);
			}
			g.fillRect(HELP_POSITION, HELP_POSITION, size+HELP_SIZE, size+HELP_SIZE);
		}
		if(help){
			g.setColor(java.awt.Color.RED);
			g.fillRect(POSITION, POSITION, size, size);
			g.setColor(java.awt.Color.BLACK);
			if(Color.White.equals(color)){
				g.setColor(java.awt.Color.WHITE);
			}
			g.fillRect(HELP_POSITION, HELP_POSITION, size+HELP_SIZE, size+HELP_SIZE);
		}
		if(!selected && !help){
			g.setColor(java.awt.Color.BLACK);
			if(Color.White.equals(color)){
				g.setColor(java.awt.Color.WHITE);
				g.fillRect(POSITION, POSITION, size, size);
			}else if(Color.Black.equals(color)){
				g.setColor(java.awt.Color.BLACK);
				g.fillRect(POSITION, POSITION, size, size);
			}
		}
		if(image != null){
			g.drawImage(image, POSITION, POSITION, null);
		}
	}

}
